// 创建文件: D:\IDEAProject\ncu\housinghubfront\src\views\admin\WelcomeView.vue
<template>
  <div class="admin-welcome-container">
    <!-- 背景装饰元素 -->
    <div class="background-decoration">
      <!-- 以房子为结构的炫酷动态背景 -->
      <div class="house-structure-background">
        <!-- 主体建筑结构 -->
        <div class="main-building">
          <!-- 建筑物主体 -->
          <div class="building-body"></div>

          <!-- 窗户网格 -->
          <div class="window-grid">
            <div class="window-row" v-for="row in 6" :key="row">
              <div class="window" v-for="col in 5" :key="col" :class="`window-${row}-${col}`"></div>
            </div>
          </div>

          <!-- 建筑顶部装饰 -->
          <div class="building-top"></div>

          <!-- 建筑底部基座 -->
          <div class="building-base"></div>
        </div>

        <!-- 周围建筑 -->
        <div class="surrounding-building building-left"></div>
        <div class="surrounding-building building-right"></div>

        <!-- 科技光环 -->
        <div class="tech-halo halo-1"></div>
        <div class="tech-halo halo-2"></div>
        <div class="tech-halo halo-3"></div>

        <!-- 数据流 -->
        <div class="data-stream stream-1"></div>
        <div class="data-stream stream-2"></div>
        <div class="data-stream stream-3"></div>
        <div class="data-stream stream-4"></div>

        <!-- 科技粒子 -->
        <div class="tech-particle particle-1"></div>
        <div class="tech-particle particle-2"></div>
        <div class="tech-particle particle-3"></div>
        <div class="tech-particle particle-4"></div>
        <div class="tech-particle particle-5"></div>
        <div class="tech-particle particle-6"></div>
        <div class="tech-particle particle-7"></div>
        <div class="tech-particle particle-8"></div>
        <div class="tech-particle particle-9"></div>
        <div class="tech-particle particle-10"></div>

        <!-- 电路节点 -->
        <div class="circuit-node node-1"></div>
        <div class="circuit-node node-2"></div>
        <div class="circuit-node node-3"></div>
        <div class="circuit-node node-4"></div>
        <div class="circuit-node node-5"></div>

        <!-- 光效 -->
        <div class="light-beam beam-1"></div>
        <div class="light-beam beam-2"></div>
        <div class="light-beam beam-3"></div>

        <!-- 扫描线 -->
        <div class="scan-line"></div>
      </div>

      <!-- 浮动装饰元素 -->
      <div class="floating-shape shape-1"></div>
      <div class="floating-shape shape-2"></div>
      <div class="floating-shape shape-3"></div>
    </div>

    <div class="admin-welcome-wrapper">
      <!-- 顶部导航栏 -->
      <div class="top-navbar">
        <div class="navbar-left">
          <h1 class="app-title">HousingHub 管理系统</h1>
        </div>
        <div class="navbar-right">
          <el-dropdown @command="handleUserCommand">
            <span class="user-info">
              <el-avatar :size="32" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png" />
              <span class="username">管理员</span>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item command="profile">个人资料</el-dropdown-item>
                <el-dropdown-item command="settings">系统设置</el-dropdown-item>
                <el-dropdown-item command="logout" divided>退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </div>

      <div class="main-content">
        <!-- 侧边栏菜单 -->
        <AdminSidebar :active-menu="activeMenu" />

        <!-- 主内容区域 -->
        <div class="content-area">
          <div class="welcome-content">
            <div class="welcome-header">
              <h1>欢迎使用 HousingHub 管理系统</h1>
              <p>在这里您可以管理房源、用户和系统设置</p>
            </div>

            <div class="quick-actions">
              <el-row :gutter="20">
                <el-col :span="6">
                  <div class="action-card" @click="goToHouseVerification">
                    <div class="action-icon bg-blue">
                      <DocumentChecked />
                    </div>
                    <div class="action-content">
                      <h3>房源审核</h3>
                      <p>{{ pendingHouses }} 个待审核</p>
                    </div>
                  </div>
                </el-col>
                <el-col :span="6">
                  <div class="action-card" @click="goToAgentVerification">
                    <div class="action-icon bg-green">
                      <User />
                    </div>
                    <div class="action-content">
                      <h3>中介审核</h3>
                      <p>{{ pendingAgents }} 个待审核</p>
                    </div>
                  </div>
                </el-col>
                <el-col :span="6">
                  <div class="action-card" @click="goToUserManagement">
                    <div class="action-icon bg-orange">
                      <UserFilled />
                    </div>
                    <div class="action-content">
                      <h3>用户管理</h3>
                      <p>{{ totalUsers }} 个用户</p>
                    </div>
                  </div>
                </el-col>
                <el-col :span="6">
                  <div class="action-card" @click="goToSystemSettings">
                    <div class="action-icon bg-red">
                      <Setting />
                    </div>
                    <div class="action-content">
                      <h3>系统设置</h3>
                      <p>配置系统参数</p>
                    </div>
                  </div>
                </el-col>
              </el-row>
            </div>

            <div class="system-info">
              <el-row :gutter="20">
                <el-col :span="12">
                  <div class="info-card">
                    <h3>系统概览</h3>
                    <el-descriptions :column="1" border>
                      <el-descriptions-item label="系统版本">v1.0.0</el-descriptions-item>
                      <el-descriptions-item label="运行时间">2025-08-04</el-descriptions-item>
                      <el-descriptions-item label="在线用户">{{ onlineUsers }} 人</el-descriptions-item>
                      <el-descriptions-item label="系统状态">
                        <el-tag type="success">正常运行</el-tag>
                      </el-descriptions-item>
                    </el-descriptions>
                  </div>
                </el-col>
                <el-col :span="12">
                  <div class="info-card">
                    <h3>最近活动</h3>
                    <el-table :data="recentActivities" style="width: 100%">
                      <el-table-column prop="time" label="时间" width="180"></el-table-column>
                      <el-table-column prop="user" label="用户" width="120"></el-table-column>
                      <el-table-column prop="action" label="操作"></el-table-column>
                    </el-table>
                  </div>
                </el-col>
              </el-row>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import AdminSidebar from '@/components/admin/AdminSidebar.vue'
import { adminLogout } from '@/utils/auth'
import {
  DocumentChecked,
  User,
  UserFilled,
  Setting
} from '@element-plus/icons-vue'

const router = useRouter()
const activeMenu = ref('dashboard')

// 数据统计
const pendingHouses = ref(12)
const pendingAgents = ref(5)
const totalUsers = ref(1280)
const onlineUsers = ref(42)

// 最近活动数据
const recentActivities = ref([
  {
    time: '2025-08-04 14:30:22',
    user: '管理员',
    action: '登录系统'
  },
  {
    time: '2025-08-04 13:45:10',
    user: '张三',
    action: '发布新房源'
  },
  {
    time: '2025-08-04 12:15:45',
    user: '李四',
    action: '签约合同'
  },
  {
    time: '2025-08-04 10:30:12',
    user: '王五',
    action: '房源审核通过'
  }
])

// 快捷操作跳转
const goToHouseVerification = () => {
  router.push('/admin/house-verification')
}

const goToAgentVerification = () => {
  router.push('/admin/agent-verification')
}

const goToUserManagement = () => {
  router.push('/admin/user-management')
}

const goToSystemSettings = () => {
  router.push('/admin/system-settings')
}

// 用户命令处理
const handleUserCommand = async (command) => {
  switch (command) {
    case 'profile':
      ElMessage.info('查看个人资料')
      break
    case 'settings':
      ElMessage.info('系统设置')
      break
    case 'logout':
      ElMessageBox.confirm('确定要退出登录吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        try {
          await adminLogout()
          ElMessage.success('退出登录成功')
          router.push('/admin-login')
        } catch (error) {
          console.error('管理员登出失败:', error)
          // 即使登出API失败，也要清除本地状态并跳转
          ElMessage.success('退出登录成功')
          router.push('/admin-login')
        }
      })
      break
  }
}
</script>

<style scoped>
.admin-welcome-container {
  display: flex;
  min-height: 100vh;
  overflow: hidden;
  position: relative;
  background: linear-gradient(135deg, #0f2027 0%, #203a43 50%, #2c5364 100%);
}

.background-decoration {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: 0;
}

/* 以房子为结构的炫酷动态背景 */
.house-structure-background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* 主体建筑结构 */
.main-building {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 300px;
  height: 400px;
}

.building-body {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 200px;
  height: 350px;
  background: linear-gradient(180deg, #1a2a6c, #2a4b8d, #3a6cb0);
  border-radius: 5px 5px 0 0;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.5);
}

/* 窗户网格 */
.window-grid {
  position: absolute;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  width: 180px;
  height: 300px;
}

.window-row {
  display: flex;
  justify-content: space-around;
  margin-bottom: 20px;
}

.window {
  width: 20px;
  height: 30px;
  background: rgba(0, 195, 255, 0.3);
  border-radius: 2px;
  box-shadow: 0 0 10px rgba(0, 195, 255, 0.5);
  animation: windowGlow 3s infinite alternate;
}

.window:nth-child(odd) {
  animation-delay: 0.5s;
}

.window:nth-child(even) {
  animation-delay: 1s;
}

@keyframes windowGlow {
  0% {
    background: rgba(0, 195, 255, 0.3);
    box-shadow: 0 0 10px rgba(0, 195, 255, 0.5);
  }
  100% {
    background: rgba(0, 195, 255, 0.7);
    box-shadow: 0 0 20px rgba(0, 195, 255, 0.9);
  }
}

/* 建筑顶部装饰 */
.building-top {
  position: absolute;
  bottom: 350px;
  left: 50%;
  transform: translateX(-50%);
  width: 220px;
  height: 30px;
  background: linear-gradient(90deg, #00c3ff, #ffff1c);
  border-radius: 5px 5px 0 0;
  box-shadow: 0 -5px 15px rgba(0, 195, 255, 0.7);
}

/* 建筑底部基座 */
.building-base {
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  width: 250px;
  height: 40px;
  background: linear-gradient(90deg, #1a2a6c, #2a4b8d);
  border-radius: 5px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
}

/* 周围建筑 */
.surrounding-building {
  position: absolute;
  bottom: 0;
  width: 150px;
  height: 300px;
  background: linear-gradient(180deg, #2a4b8d, #1a2a6c);
  border-radius: 5px 5px 0 0;
  box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.4);
}

.building-left {
  left: 20%;
}

.building-right {
  right: 20%;
}

/* 科技光环 */
.tech-halo {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(0, 195, 255, 0.2) 0%, transparent 70%);
  animation: rotateHalo 20s infinite linear;
}

.halo-1 {
  top: 20%;
  left: 10%;
  width: 300px;
  height: 300px;
  animation-duration: 25s;
}

.halo-2 {
  top: 40%;
  right: 15%;
  width: 200px;
  height: 200px;
  animation-duration: 30s;
  animation-direction: reverse;
}

.halo-3 {
  bottom: 30%;
  left: 30%;
  width: 150px;
  height: 150px;
  animation-duration: 20s;
}

@keyframes rotateHalo {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* 数据流 */
.data-stream {
  position: absolute;
  background: linear-gradient(90deg, transparent, rgba(0, 195, 255, 0.5), transparent);
  height: 2px;
  animation: dataFlow 5s infinite linear;
}

.stream-1 {
  top: 20%;
  left: -100%;
  width: 200px;
  animation-delay: 0s;
}

.stream-2 {
  top: 40%;
  right: -100%;
  width: 300px;
  animation-delay: 1s;
  animation-duration: 6s;
}

.stream-3 {
  top: 60%;
  left: -100%;
  width: 250px;
  animation-delay: 2s;
  animation-duration: 7s;
}

.stream-4 {
  top: 80%;
  right: -100%;
  width: 150px;
  animation-delay: 3s;
  animation-duration: 4s;
}

@keyframes dataFlow {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(calc(100vw + 200px));
  }
}

/* 科技粒子 */
.tech-particle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: #00c3ff;
  border-radius: 50%;
  box-shadow: 0 0 10px #00c3ff;
  animation: floatParticle 10s infinite linear;
}

.particle-1 {
  top: 10%;
  left: 20%;
  animation-delay: 0s;
}

.particle-2 {
  top: 30%;
  right: 20%;
  animation-delay: 1s;
}

.particle-3 {
  top: 50%;
  left: 10%;
  animation-delay: 2s;
}

.particle-4 {
  top: 70%;
  right: 30%;
  animation-delay: 3s;
}

.particle-5 {
  top: 20%;
  left: 40%;
  animation-delay: 4s;
}

.particle-6 {
  top: 40%;
  right: 10%;
  animation-delay: 5s;
}

.particle-7 {
  top: 60%;
  left: 30%;
  animation-delay: 6s;
}

.particle-8 {
  top: 80%;
  right: 40%;
  animation-delay: 7s;
}

.particle-9 {
  top: 15%;
  left: 60%;
  animation-delay: 8s;
}

.particle-10 {
  top: 75%;
  right: 25%;
  animation-delay: 9s;
}

@keyframes floatParticle {
  0% {
    transform: translate(0, 0);
  }
  25% {
    transform: translate(50px, 30px);
  }
  50% {
    transform: translate(100px, 0);
  }
  75% {
    transform: translate(50px, -30px);
  }
  100% {
    transform: translate(0, 0);
  }
}

/* 电路节点 */
.circuit-node {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #00c3ff;
  border-radius: 50%;
  box-shadow: 0 0 15px #00c3ff;
  animation: pulseNode 2s infinite;
}

.node-1 {
  top: 25%;
  left: 25%;
  animation-delay: 0s;
}

.node-2 {
  top: 35%;
  right: 25%;
  animation-delay: 0.5s;
}

.node-3 {
  top: 45%;
  left: 35%;
  animation-delay: 1s;
}

.node-4 {
  bottom: 35%;
  right: 35%;
  animation-delay: 1.5s;
}

.node-5 {
  bottom: 25%;
  left: 45%;
  animation-delay: 2s;
}

@keyframes pulseNode {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.5);
    opacity: 0.7;
  }
}

/* 光效 */
.light-beam {
  position: absolute;
  background: linear-gradient(90deg, transparent, rgba(0, 195, 255, 0.3), transparent);
  height: 100px;
  width: 10px;
  transform-origin: top center;
  animation: rotateBeam 15s infinite linear;
}

.beam-1 {
  top: 0;
  left: 30%;
  animation-delay: 0s;
}

.beam-2 {
  top: 0;
  left: 50%;
  animation-delay: 5s;
  animation-duration: 20s;
}

.beam-3 {
  top: 0;
  left: 70%;
  animation-delay: 10s;
  animation-duration: 25s;
}

@keyframes rotateBeam {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* 扫描线 */
.scan-line {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(0, 195, 255, 0.8), transparent);
  animation: scan 5s infinite linear;
  box-shadow: 0 0 10px rgba(0, 195, 255, 0.8);
}

@keyframes scan {
  0% {
    top: 0;
  }
  100% {
    top: 100%;
  }
}

/* 浮动装饰元素 */
.floating-shape {
  position: absolute;
  border-radius: 50%;
  background: rgba(0, 195, 255, 0.1);
  animation: float 15s infinite linear;
}

.shape-1 {
  width: 300px;
  height: 300px;
  top: -100px;
  left: -100px;
  animation-duration: 20s;
  background: radial-gradient(circle, rgba(0, 195, 255, 0.2) 0%, transparent 70%);
}

.shape-2 {
  width: 200px;
  height: 200px;
  bottom: -80px;
  right: -80px;
  animation-duration: 25s;
  animation-direction: reverse;
  background: radial-gradient(circle, rgba(0, 195, 255, 0.2) 0%, transparent 70%);
}

.shape-3 {
  width: 150px;
  height: 150px;
  top: 30%;
  right: 20%;
  animation-duration: 15s;
  background: radial-gradient(circle, rgba(0, 195, 255, 0.2) 0%, transparent 70%);
}

@keyframes float {
  0% {
    transform: translate(0, 0) rotate(0deg);
  }
  25% {
    transform: translate(20px, 20px) rotate(90deg);
  }
  50% {
    transform: translate(0, 40px) rotate(180deg);
  }
  75% {
    transform: translate(-20px, 20px) rotate(270deg);
  }
  100% {
    transform: translate(0, 0) rotate(360deg);
  }
}

.admin-welcome-wrapper {
  width: 100%;
  height: 100vh;
  z-index: 1;
  display: flex;
  flex-direction: column;
}

.top-navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 30px;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(10px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.navbar-left {
  display: flex;
  align-items: center;
  gap: 15px;
}

.navbar-right {
  display: flex;
  align-items: center;
}

.app-title {
  color: #00c3ff;
  font-size: 24px;
  font-weight: 700;
  margin: 0;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  color: white;
}

.username {
  font-size: 16px;
  font-weight: 500;
}

.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.content-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  overflow-y: auto;
  padding: 20px;
}

.welcome-content {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.welcome-header {
  text-align: center;
  margin-bottom: 40px;
}

.welcome-header h1 {
  color: #2c3e50;
  font-size: 32px;
  font-weight: 700;
  margin: 0 0 15px 0;
}

.welcome-header p {
  color: #7f8c8d;
  font-size: 18px;
  margin: 0;
}

.quick-actions {
  margin-bottom: 40px;
}

.action-card {
  display: flex;
  background: white;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  cursor: pointer;
}

.action-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}

.action-icon {
  width: 60px;
  height: 60px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 15px;
  flex-shrink: 0;
}

.action-icon.bg-blue {
  background: linear-gradient(135deg, #00c3ff, #0066cc);
}

.action-icon.bg-green {
  background: linear-gradient(135deg, #00b09b, #96c93d);
}

.action-icon.bg-orange {
  background: linear-gradient(135deg, #ff9a9e, #fad0c4);
}

.action-icon.bg-red {
  background: linear-gradient(135deg, #ff5e62, #ff9966);
}

.action-content h3 {
  color: #2c3e50;
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 8px 0;
}

.action-content p {
  color: #7f8c8d;
  font-size: 14px;
  margin: 0;
}

.system-info {
  flex: 1;
}

.info-card {
  background: white;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  margin-bottom: 20px;
}

.info-card h3 {
  color: #2c3e50;
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 20px 0;
}

@media (max-width: 992px) {
  .quick-actions .el-col {
    margin-bottom: 20px;
  }

  .system-info .el-col {
    margin-bottom: 20px;
  }
}
</style>
